<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script src="./lib/vue.js"></script>
</body>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./lib/vue.js"></script>
</head>

<body>
  <div id="app">
    <input type="checkbox" v-model="checked" @change="selectAll">{{checked?'取消全选':'全选'}}
    <hr>
    <div v-for="item in lessons" :key="item">
      <input type="checkbox" :value="item" v-model="checkedNames" @change="changeItem">{{item}}
    </div>

  </div>

  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        lessons: ['html', 'css', 'js'],
        checked: false,
        checkedNames: []
      },
      methods: {
        selectAll() {
          if (this.checked) {
            this.checkedNames = this.lessons
          } else {
            this.checkedNames = []
          }
        },
        changeItem(evt){
          // if(evt.target.checked){ // 选中
            this.checked = (this.lessons.length === this.checkedNames.length)
          // }
        }
      }
    })
  </script>
</body>

</html>